package com.lwf.thymeleafdemo1.exception.controller;


import com.lwf.thymeleafdemo1.exception.Enum.ExceptionEnum;
import com.lwf.thymeleafdemo1.exception.dto.UserInfo;
import com.lwf.thymeleafdemo1.exception.entiry.Result;
import com.lwf.thymeleafdemo1.exception.utils.ExceptionHandle;
import com.lwf.thymeleafdemo1.exception.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author liwenfeng
 * @Description dongruan
 * @Date 2023/08/11/9:45
 * @Version 1.0
 */
@RestController
@Controller
@RequestMapping("/result")
public class ResultController {

    @Autowired
    private ExceptionHandle exceptionHandle;

    /**
     * 返回体测试
     *
     * @param name
     * @param pwd
     * @return
     */
    @PostMapping(value = "/getResult")
    public Result getResult(@RequestParam("name") String name, @RequestParam("pwd") String pwd) {
        Result result = ResultUtil.success();
        try {
            if (name.equals("zzp")) {
                result = ResultUtil.success(new UserInfo("张三", 18, "湖北"));
            } else if (name.equals("pzz")) {
                result = ResultUtil.error(ExceptionEnum.USER_NOT_FIND);
            } else {
                int i = 1 / 0;
            }
        } catch (Exception e) {
            result = exceptionHandle.exceptionGet(e);
        }
        return result;
    }
}
